package cn.stylefeng.guns.modular.system.utils;


import cn.stylefeng.guns.modular.system.exception.ProjectException;
import cn.stylefeng.guns.modular.system.vo.ResultVO;

/**
 * @Author: lzy
 * @Date: 2020/1/2 11:23
 * @Version 1.0
 */
public class ResultVOUtil {
    /**
     * 成功就调用这个方法
     * @param object
     * @return
     */
    public static ResultVO success(Object... object){
        ResultVO resultVO = new ResultVO();
        resultVO.setData(object[0]);
        resultVO.setMsg("SECCESS");
        resultVO.setCode(0);
        if(object.length > 1){
            resultVO.setCount(Integer.parseInt(object[1].toString()));
        }else{
            resultVO.setCount(0);
        }
        return resultVO;
    }

    /**
     * 如果传入的数据为null
     * @return
     */
    public static ResultVO success(String msg){
        ResultVO resultVO = new ResultVO();
        resultVO.setData(null);
        resultVO.setMsg(msg);
        resultVO.setCode(0);
        resultVO.setCount(0);
        return resultVO;
    }

    public static ResultVO error(Integer code, String msg){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setCount(0);
        return resultVO;
    }
    public static ResultVO error(Exception ex) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(500);
        resultVO.setMsg(ex.getMessage());
        resultVO.setCount(0);
        return resultVO;
    }
}
